import os
import re
import threading
import time


# def main():
#     # 只能遍历一层目录
#     local_dir = '/work/grafana-agent/'
#     for filename in os.listdir(local_dir):
#         file_path = os.path.join(local_dir, filename)
#         if os.path.isfile(file_path):
#             print(f'{file_path}')


def list_files(startpath):
    for root, dirs, files in os.walk(startpath):
        # 遍历当前目录下的文件
        for file in files:
            fullname = os.path.join(root, file)
            print(f'{root} -- {file}')
            yield fullname

def work():
    time.sleep(5)

# def main():
    # for i in list_files('/work/grafana-agent/'):
    #     print(i)

    # local_path = '/work/grafana-agent/'
    # remote_path = '/work/'
    # file = '/work/grafana-agent/a948b118ab78d6d00330c496c827a5af/wal/checkpoint.00000322/00000000'
    # # file 去掉 local_path  替换成 remote_path
    # l = file.split(local_path)
    # a = os.path.join(remote_path, l[1])
    # f = '00000000'
    # a.split(f)
    # print( a.split(f))

    # import os
    # from datetime import datetime
    #
    # # 获取文件最后修改时间
    # mtime = os.path.getmtime('/work/work/secure')
    #
    # # 将时间戳转换成 datetime 对象
    # last_modified_time = datetime.fromtimestamp(mtime)
    # print(last_modified_time)
    #


if __name__ == '__main__':
    # main()
    # 调用函数开始遍历
    # list_files("/work/grafana-agent/")

    # import time
    #
    # local_timezone = time.timezone / 3600  # 获取本地时区偏移量，单位为秒
    # print("本地时区偏移量:", local_timezone)
    #
    # # 如果您需要获取本地时区的名称，可以使用以下代码
    # local_timezone_name = time.tzname[0] if time.tzname else "Unknown"
    # print("本地时区名称:", local_timezone_name)

    # for thread in threading.enumerate():
    #     print(thread.name)
        # if re.search(r'_thread\b', thread.name):
        #     print(thread.name)

    variable = f"{1}"  # 这里代表您的变量
    pattern = rf"^{variable}_\w+_thread$"

    print(pattern)
    if re.search(pattern, "sync_1_2_thread"):
        print('qqq')
    else:
        print('ee')

